package com.itcast.demoone

import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class ButtonActivity : AppCompatActivity(), View.OnClickListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_button)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        // 获取点击的按钮
        /*val btn2 = findViewById<View>(R.id.btn2)
        btn2.setOnClickListener {
            Toast.makeText(this, "点击了按钮2", Toast.LENGTH_SHORT).show()
        }*/

        // 完成按钮委托监听
        findViewById<View>(R.id.btn2).setOnClickListener(this)
        findViewById<View>(R.id.btn3).setOnClickListener(this)
    }

    fun onBtnClick(view: View){
        Toast.makeText(this, "点击了按钮11", Toast.LENGTH_SHORT).show()
    }

    override fun onClick(v: View?) {
       // Toast.makeText(this, "666666", Toast.LENGTH_SHORT).show()
        when(v?.id){
            R.id.btn2 -> Toast.makeText(this, "点击了按钮2", Toast.LENGTH_SHORT).show()
            R.id.btn3 -> Toast.makeText(this, "点击了按钮3", Toast.LENGTH_SHORT).show()
        }
    }
}